package com.lctandil.geophotos;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import com.lctandil.geophotos.R;
import com.lctandil.geophotos.data.ImageLoader;

public class Splay_Activity extends Activity {

	protected boolean _active = true;
	protected long _splashTime = 3000; // time to display the splash screen in
										// ms

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splay_);
		Handler handler = new Handler();
		handler.postDelayed(getRunnableStartApp(),100);
	}

	private Runnable getRunnableStartApp() {
		Runnable runnable = new Runnable() {
			public void run() {
				long time = System.currentTimeMillis();

				ImageLoader.loadCameraImages(getApplicationContext());

				long past = System.currentTimeMillis() - time;
				if (past < _splashTime) {
					try {
						Thread.sleep(_splashTime - past);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				Intent intent = new Intent(Splay_Activity.this,
						MainActivity.class);
				startActivity(intent);
				finish();
			}
		};
		return runnable;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			_active = false;
		}
		return true;
	}

}
